﻿using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.Collection;
using LdtJudge.DataEngine.Model.CommModel;
using MQModelHandleLibaryCore.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LdtJudge.DataEngine.From.Control
{
    public class RealizationClass
    {
        public enum FontStyles
        {
            defult,
            style1,
            style2,
            style3,
            style4,
            style5,
            style6,
            style7,
            style8,
            style9,
            style10
        }
        /// <summary>
        /// MQ链接对象
        /// </summary>
        public ConnectionConfig Connection { get; set; }

        #region 分析文书实现方法
        /// <summary>
        /// 完成时间
        /// </summary>
        /// <param name="time">The time.</param>
        public void FinishAnalysisTimeP(long time, BufferModel bufferModel)
        {
            //if (bufferModel != null)
            //{
            //    //AnalysisFinish analysisFinish = new AnalysisFinish()
            //    //{
            //    //    CaseID = bufferModel.CaseID,
            //    //    FilePath = bufferModel.FilePath,
            //    //    OutRelatID = bufferModel.OutRelatID,
            //    //    SourceName = bufferModel.SourceName,
            //    //    Result = "true"
            //    //};
            //    //string message = JsonConvert.SerializeObject(analysisFinish);
            //    //进行发布消息
            //    // PublishMessage.publishMessage.ExchangePublishMessage("result", message);
            //    //AnalysisTextLog("分析完毕：" + message);
            //}

            //Tuple<string, BufferModel, long> tulpeTemp = new Tuple<string, BufferModel, long>("timep", bufferModel, time);
            //QueueMessage.Enqueue(tulpeTemp);
        }

        /// <summary>
        /// 当前运行模块
        /// </summary>
        /// <param name="moduleName"></param>
        /// <param name="processValue"></param>
        public void SetModuleProcess(string moduleName, int processValue, MainInputParameterModel inputParameterModel)
        { 
        
        }
        /// <summary>
        /// 执行完成模块
        /// </summary>
        /// <param name="mdoelstring"></param>
        /// <param name="type"></param>
        public void ModularModelSet(string mdoelstring, string type, MainInputParameterModel inputParameterModel)
        { 
        
        }
        /// <summary>
        /// 执行完成模块
        /// </summary>
        /// <param name="mdoelstring"></param>
        /// <param name="type"></param>
        public void ModularModelSet(string mdoelstring, int type)
        {

        }
        /// <summary>
        /// 进度
        /// </summary>
        /// <param name="fileId"></param>
        /// <param name="nvalue"></param>
        public void ProcessShow(string fileId, int nvalue, MainInputParameterModel inputParameterModel) 
        {
        
        
        }

        /// <summary>
        /// 导入或者优选结束回调
        /// </summary>
        public void FinishP(BufferModel bufferModel)
        {
            //if (bufferModel != null)
            //{
            //    AnalysisFinish analysisFinish = new AnalysisFinish()
            //    {
            //        CaseID = bufferModel.CaseID,
            //        FilePath = bufferModel.FilePath,
            //        OutRelatID = bufferModel.OutRelatID,
            //        SourceName = bufferModel.SourceName,
            //        Result = "true"

            //    };
            //string message = ConfigManagerHandle.ReturnJsonString(analysisFinish);
            //进行发布消息
            //bufferModel.JosnId = "99";
            // PublishMessage.publishMessage.ExchangePublishMessage("result", message);
            //if (!string.IsNullOrEmpty(bufferModel.IP) && !string.IsNullOrEmpty(bufferModel.JosnId))
            //    //PublishMessage.publishMessage.ExchangePublishMessage(bufferModel.IP, bufferModel.JosnId);
            //    MQModelHandleLibaryCore.RoutingHandle.RoutSend.RoutSendInstance.SendMessage(bufferModel.IP, bufferModel.JosnId);
            //AnalysisTextLog("分析完毕：" + message + " 解析IP：" + bufferModel.IP + "  解析ID：" + bufferModel.JosnId);

            //try
            //{
            //    HandleProgressModel handleProgressModel = new HandleProgressModel();
            //    handleProgressModel.HandleType = bufferModel.HandleType;
            //    handleProgressModel.MsgId = bufferModel.MsgId;

            //    CaseInfo caseInfo = new CaseInfo();
            //    caseInfo.OutRealtId = bufferModel.OutRelatID;
            //    handleProgressModel.ProgressValue ="100";
            //    handleProgressModel.CaseInfo = caseInfo;
            //    DocInfol docInfol = new DocInfol();
            //    docInfol.FileId = bufferModel.FilePath;
            //    docInfol.SourceCode = bufferModel.SourceCode;
            //    handleProgressModel.DocInfo = docInfol;

            //    string messages = JsonConvert.SerializeObject(handleProgressModel);

            //    string path = ConfigurationManager.AppSettings["WebPath"];
            //    HTTPVisit hTTPVisit = new HTTPVisit();
            //    Dictionary<string, string> dicValue = new Dictionary<string, string>();
            //    dicValue.Add("type", "2");
            //    dicValue.Add("message", messages);
            //    hTTPVisit.CreatePostHttpResponse(path, dicValue);
            //}
            //catch (Exception)
            //{


            //}
            //}
        }

        /// <summary>
        /// 进度条显示
        /// </summary>
        /// <param name="fileIndex">文件序号</param>
        /// <param name="totalNumb">总文件数</param>
        /// <param name="filepath">文件路径</param>
        /// <param name="processValue">进度条值</param>
        public void ProcessShowP(int fileIndex, int totalNumb, string filePath, int nvalue, BufferModel bufferModel, int processValue)
        {
            if (bufferModel != null)
            {
                processValue = nvalue;
                if (processValue > 100)
                {
                    processValue = 100;
                }
                HandleProgressModel handleProgressModel = new HandleProgressModel();
                handleProgressModel.HandleType = bufferModel.HandleType;
                handleProgressModel.MsgId = bufferModel.MsgId;

                CaseInfo caseInfo = new CaseInfo();
                caseInfo.OutRealtId = bufferModel.OutRelatID;
                handleProgressModel.ProgressValue = processValue.ToString();
                handleProgressModel.CaseInfo = caseInfo;
                DocInfol docInfol = new DocInfol();
                docInfol.FileId = bufferModel.FilePath;
                docInfol.SourceCode = bufferModel.SourceCode;
                handleProgressModel.DocInfo = docInfol;
                
                string message = JsonConvert.SerializeObject(handleProgressModel);
                //进行发布消息
                MQModelHandleLibaryCore.PublishSubscribeHandle.PublishSubscribeSend.PublishMessageShort(Connection, new ExchangeModel() { ExchangeName = "HandleProgressExchange", ExchangeDurable = true }, "HandleProgress", message, 5);
                //MQModelHandleLibaryCore.PublishSubscribeHandle.PublishSubscribeSend.PublishMessageShort(Connection, new ExchangeModel() { ExchangeName = "HandleProgressExchange", ExchangeDurable = true }, "HandleProgress", message, MQBaseConfig.MessagePriority.Normal);
            }

        }
        #endregion

        /// <summary>
        /// 显示后台日志wxlu
        /// </summary>
        /// <param name="log"></param>
        public void ShowMessage(string log, LogMessageType messagetype = LogMessageType.Info)
        {
            LogShowFontStyle(log, FontStyles.defult);
        }
        /// <summary>
        /// 日志显示有字体样式
        /// </summary>
        /// <param name="logInfo">日志</param>
        /// <param name="fontStyles">日志样式</param>
        public void LogShowFontStyle(string logInfo, FontStyles fontStyles)
        {
            
        }
        
    }
}
